package com.example.jedis.client.command.key;

import com.example.jedis.client.command.constant.RedisCommandConstant;
import com.example.jedis.client.protocol.constant.RedisProtocolConstant;
import com.example.jedis.client.protocol.request.RequestProtocol;
import com.example.jedis.client.protocol.response.ResponseProtocol;
import com.example.jedis.client.utils.RedisProtocolUtils;

public class RedisKeyCommandImpl  implements RedisKeyCommand{
    RequestProtocol requestProtocol = null;
    ResponseProtocol responseProtocol = null;

    public RequestProtocol getRequestProtocol() {
        return requestProtocol;
    }

    public void setRequestProtocol(RequestProtocol requestProtocol) {
        this.requestProtocol = requestProtocol;
    }

    public ResponseProtocol getResponseProtocol() {
        return responseProtocol;
    }

    public void setResponseProtocol(ResponseProtocol responseProtocol) {
        this.responseProtocol = responseProtocol;
    }

    public Integer del(String ...keys){
        byte [][] bytes = new byte [keys.length+1][];
        for(int i=0;i<keys.length;i++){
            bytes[i+1] = RedisProtocolUtils.toBytes(keys[i]);
        }
        bytes[0] = RedisCommandConstant.COMMAND_DEL_BYTES;
        requestProtocol.write(bytes);
        return (Integer)responseProtocol.read();
    }

    @Override
    public Integer ttl(String key) {
        requestProtocol.write(RedisCommandConstant.COMMAND_TTL_BYTES,RedisProtocolUtils.toBytes(key));
        return (Integer)responseProtocol.read();
    }

    @Override
    public Integer exists(String key) {
        return null;
    }
}
